import { FormItemConfig } from '../types/form';

/**
 * 产品表单配置
 */
export const productFormConfig: FormItemConfig[] = [
  {
    name: 'code',
    label: '物品编号',
    type: 'input',
    placeholder: '请输入物品编号',
    rules: [
      { required: true, message: '请输入物品编号' },
      { max: 50, message: '编号长度不能超过50个字符' }
    ]
  },
  {
    name: 'name',
    label: '物品名称',
    type: 'input',
    placeholder: '请输入物品名称',
    rules: [
      { required: true, message: '请输入物品名称' },
      { max: 100, message: '名称长度不能超过100个字符' }
    ]
  },
  {
    name: 'warning',
    label: '预警库存',
    type: 'number',
    placeholder: '请输入预警库存',
    rules: [
      { required: true, message: '请输入预警库存' },
      { 
        validator: (_, value) => {
          if (value === null || value === undefined || value === '') {
            return Promise.reject(new Error('请输入预警库存'));
          }
          if (typeof value === 'number' && value < 0) {
            return Promise.reject(new Error('库存不能为负数'));
          }
          return Promise.resolve();
        }
      }
    ]
  },
  {
    name: 'cate',
    label: '分类',
    type: 'select',
    placeholder: '请选择分类',
    rules: [{ required: true, message: '请选择分类' }],
    options: [
      { label: '小家电', value: '小家电' },
      { label: '大家电', value: '大家电' },
      { label: '数码产品', value: '数码产品' },
      { label: '办公用品', value: '办公用品' }
    ]
  }
];

/**
 * 仓库表单配置
 */
export const warehouseFormConfig: FormItemConfig[] = [
  {
    name: 'code',
    label: '仓库编码',
    type: 'input',
    placeholder: '请输入仓库编码（如A01、B02）',
    rules: [
      { required: true, message: '请输入仓库编码' },
      { max: 20, message: '编码长度不能超过20个字符' },
      { pattern: /^[A-Za-z0-9]+$/, message: '编码只能包含字母和数字' }
    ]
  },
  {
    name: 'name',
    label: '仓库名称',
    type: 'input',
    placeholder: '请输入仓库名称（如生鲜A仓、食品B仓）',
    rules: [
      { required: true, message: '请输入仓库名称' },
      { max: 50, message: '名称长度不能超过50个字符' },
      { pattern: /^[^<>]*$/, message: '名称不能包含<>特殊字符' }
    ]
  },
  {
    name: 'remark',
    label: '仓库备注',
    type: 'textarea',
    placeholder: '请输入仓库备注（如存储品类、环境要求等，非必填）',
    rules: [
      { max: 200, message: '备注长度不能超过200个字符' }
    ]
  }
];

/**
 * 用户表单配置
 */
export const userFormConfig: FormItemConfig[] = [
  {
    name: 'username',
    label: '用户名',
    type: 'input',
    placeholder: '请输入用户名',
    rules: [
      { required: true, message: '请输入用户名' },
      { max: 50, message: '用户名长度不能超过50个字符' }
    ]
  },
  {
    name: 'realName',
    label: '真实姓名',
    type: 'input',
    placeholder: '请输入真实姓名',
    rules: [
      { required: true, message: '请输入真实姓名' },
      { max: 50, message: '真实姓名长度不能超过50个字符' }
    ]
  },
  {
    name: 'phone',
    label: '手机号',
    type: 'input',
    placeholder: '请输入手机号',
    rules: [
      { required: true, message: '请输入手机号' },
      { pattern: /^1[3-9]\d{9}$/, message: '请输入有效的手机号' }
    ]
  },
  {
    name: 'department',
    label: '部门',
    type: 'select',
    placeholder: '请选择部门',
    rules: [{ required: true, message: '请选择部门' }],
    options: [
      { label: '技术部', value: '技术部' },
      { label: '仓储部', value: '仓储部' },
      { label: '财务部', value: '财务部' },
      { label: '人事部', value: '人事部' }
    ]
  },
  {
    name: 'departmentCode',
    label: '部门编码',
    type: 'number',
    placeholder: '请输入部门编码',
    rules: [
      { required: true, message: '请输入部门编码' },
      { min: 1, message: '部门编码必须大于0' }
    ]
  },
  {
    name: 'role',
    label: '角色',
    type: 'select',
    placeholder: '请选择角色',
    rules: [{ required: true, message: '请选择角色' }],
    options: [
      { label: '管理员', value: '管理员' },
      { label: '仓储经理', value: '仓储经理' },
      { label: '出库员', value: '出库员' },
      { label: '入库员', value: '入库员' }
    ]
  },
  {
    name: 'status',
    label: '状态',
    type: 'select',
    placeholder: '请选择状态',
    rules: [{ required: true, message: '请选择状态' }],
    options: [
      { label: '正常', value: '正常' },
      { label: '停用', value: '停用' }
    ]
  }
];

/**
 * 库区表单配置
 */
export const warehouseAreaFormConfig: FormItemConfig[] = [
  {
    name: 'code',
    label: '库区编码',
    type: 'input',
    placeholder: '请输入库区编码',
    rules: [
      { required: true, message: '请输入库区编码' },
      { max: 50, message: '编码长度不能超过50个字符' }
    ]
  },
  {
    name: 'name',
    label: '库区名称',
    type: 'input',
    placeholder: '请输入库区名称',
    rules: [
      { required: true, message: '请输入库区名称' },
      { max: 100, message: '名称长度不能超过100个字符' }
    ]
  },
  {
    name: 'warehouse',
    label: '所属仓库',
    type: 'select',
    placeholder: '请选择所属仓库',
    rules: [{ required: true, message: '请选择所属仓库' }],
    options: [
      { label: '生鲜A仓', value: '生鲜A仓' },
      { label: '食品B仓', value: '食品B仓' },
      { label: '日用品C仓', value: '日用品C仓' },
      { label: '家电D仓', value: '家电D仓' },
      { label: '服装E仓', value: '服装E仓' }
    ]
  }
];

/**
 * 库位表单配置
 */
export const storageLocationFormConfig: FormItemConfig[] = [
  {
    name: 'code',
    label: '库位编码',
    type: 'input',
    placeholder: '请输入库位编码',
    rules: [
      { required: true, message: '请输入库位编码' },
      { max: 50, message: '编码长度不能超过50个字符' }
    ]
  },
  {
    name: 'name',
    label: '库位名称',
    type: 'input',
    placeholder: '请输入库位名称',
    rules: [
      { required: true, message: '请输入库位名称' },
      { max: 100, message: '名称长度不能超过100个字符' }
    ]
  },
  {
    name: 'warehouse',
    label: '所属仓库',
    type: 'select',
    placeholder: '请选择所属仓库',
    rules: [{ required: true, message: '请选择所属仓库' }],
    options: [
      { label: '生鲜A仓', value: '生鲜A仓' },
      { label: '食品B仓', value: '食品B仓' },
      { label: '日用品C仓', value: '日用品C仓' },
      { label: '家电D仓', value: '家电D仓' },
      { label: '服装E仓', value: '服装E仓' }
    ]
  },
  {
    name: 'area',
    label: '所属库区',
    type: 'select',
    placeholder: '请选择所属库区',
    rules: [{ required: true, message: '请选择所属库区' }],
    options: [] // 动态选项，根据仓库选择
  },
  {
    name: 'locationType',
    label: '库位类型',
    type: 'select',
    placeholder: '请选择库位类型',
    rules: [{ required: true, message: '请选择库位类型' }],
    options: [
      { label: '货架', value: '货架' },
      { label: '地堆', value: '地堆' },
      { label: '挂架', value: '挂架' },
      { label: '冷藏架', value: '冷藏架' },
      { label: '冷冻柜', value: '冷冻柜' },
      { label: '冷藏柜', value: '冷藏柜' }
    ]
  },
  {
    name: 'status',
    label: '状态',
    type: 'select',
    placeholder: '请选择状态',
    rules: [{ required: true, message: '请选择状态' }],
    options: [
      { label: '正常', value: '正常' },
      { label: '维护中', value: '维护中' },
      { label: '故障', value: '故障' },
      { label: '闲置', value: '闲置' }
    ]
  }
];

/**
 * 部门表单配置
 */
export const departmentFormConfig: FormItemConfig[] = [
  {
    name: 'departmentCode',
    label: '部门编码',
    type: 'input',
    placeholder: '请输入部门编码',
    rules: [
      { required: true, message: '请输入部门编码' },
      { max: 20, message: '编码长度不能超过20个字符' }
    ]
  },
  {
    name: 'departmentName',
    label: '部门名称',
    type: 'input',
    placeholder: '请输入部门名称',
    rules: [
      { required: true, message: '请输入部门名称' },
      { max: 50, message: '名称长度不能超过50个字符' }
    ]
  },
  {
    name: 'creator',
    label: '创建人',
    type: 'input',
    placeholder: '请输入创建人',
    rules: [
      { required: true, message: '请输入创建人' },
      { max: 20, message: '创建人长度不能超过20个字符' }
    ]
  },
  {
    name: 'modifier',
    label: '修改人',
    type: 'input',
    placeholder: '请输入修改人',
    rules: [
      { required: true, message: '请输入修改人' },
      { max: 20, message: '修改人长度不能超过20个字符' }
    ]
  }
];

/**
 * 权限表单配置
 */
export const permissionFormConfig: FormItemConfig[] = [
  {
    name: 'roleCode',
    label: '角色编号',
    type: 'input',
    placeholder: '请输入角色编号',
    rules: [
      { required: true, message: '请输入角色编号' },
      { max: 20, message: '编号长度不能超过20个字符' }
    ]
  },
  {
    name: 'roleName',
    label: '角色名称',
    type: 'input',
    placeholder: '请输入角色名称',
    rules: [
      { required: true, message: '请输入角色名称' },
      { max: 50, message: '名称长度不能超过50个字符' }
    ]
  }
];

/**
 * 客户表单配置
 */
export const customerFormConfig: FormItemConfig[] = [
  {
    name: 'name',
    label: '客户名称',
    type: 'input',
    placeholder: '请输入客户名称',
    rules: [
      { required: true, message: '请输入客户名称' },
      { max: 100, message: '名称长度不能超过100个字符' }
    ]
  },
  {
    name: 'contact',
    label: '联系人/电话',
    type: 'input',
    placeholder: '请输入联系人/电话',
    rules: [
      { required: true, message: '请输入联系人/电话' },
      { max: 50, message: '联系人/电话长度不能超过50个字符' }
    ]
  },
  {
    name: 'type',
    label: '类型',
    type: 'select',
    placeholder: '请选择类型',
    rules: [{ required: true, message: '请选择类型' }],
    options: [
      { label: '客户', value: '客户' },
      { label: '供应商', value: '供应商' }
    ]
  }
];

/**
 * 字段表单配置
 */
export const fieldFormConfig: FormItemConfig[] = [
  {
    name: 'name',
    label: '字段名称',
    type: 'input',
    placeholder: '请输入字段名称',
    rules: [
      { required: true, message: '请输入字段名称' },
      { max: 50, message: '字段名称长度不能超过50个字符' }
    ]
  },
  {
    name: 'description',
    label: '说明',
    type: 'input',
    placeholder: '请输入说明',
    rules: [
      { required: true, message: '请输入说明' },
      { max: 100, message: '说明长度不能超过100个字符' }
    ]
  },
  {
    name: 'type',
    label: '类型',
    type: 'select',
    placeholder: '请选择类型',
    rules: [{ required: true, message: '请选择类型' }],
    options: [
      { label: '客户类型', value: '客户类型' },
      { label: '物品单位', value: '物品单位' }
    ]
  }
];
